home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / MORSE_CD / MORSE_IN.C < prev    next >
C/C++ Source or Header  |  1989-11-11  |  2KB  |  58 lines

  1. /*
  2.     This INIT will show it's ICN# and then emit some morse code,
  3.     depending on what it finds in the following resource:
  4.  
  5.     'PARM' resource -4048 contains:
  6.         1. Boolean (if TRUE then emit morse code).
  7.         2. Frequency (Hz).
  8.         3. Volume 0...255 (loudest).
  9.         4. Speed, dot time in 1/60 seconds.
  10.         5. Pascal string with text to send as morse code.
  11.  
  12.     The MorsePlay() function is in code resource 'PLAY' -4048.
  13.  
  14.     Set the project to "code resource" of type 'INIT' with custom header.
  15. */
  16.  
  17. #define ICON    -4064    /* Resource id of 'ICN#' */
  18. #define PARM    -4048    /* Resource id of 'PARM' */
  19. #define PLAY    -4048    /* Resource id of 'PLAY' */
  20.  
  21. typedef void (*PF)();    /* Pointer to function returning void */
  22.  
  23. typedef struct Parameter {    /* Structure of 'PARM' resource */
  24.     short enable;            /* Morse or not to morse that's the question */
  25.     short frequency;        /* Hz */
  26.     short volume;            /* 0..255 (loudest) */
  27.     short speed;            /* Length of dot in 1/60 seconds */
  28.     char text[256];        /* Pascal string, text to morse */
  29. } Parameter, *ParameterPtr, **ParameterHdl;
  30.  
  31. #define MorsePlay(a,b,c,d) (*mp)(a,b,c,d)
  32.  
  33. main()
  34. {
  35.     register ParameterHdl h;
  36.     register ParameterPtr p;
  37.     PF mp, *mh;
  38.  
  39.     /* Note: all registers are saved/restored by the system */
  40.  
  41.     asm { LEA main,A4 }    /* A4 used for global and static data */
  42.     if (h = (ParameterHdl)GetResource('PARM', PARM)) {
  43.         HLock(h);
  44.         p = *h;
  45.         if (p->enable) {
  46.             ShowINIT(ICON);        /* INIT notification */
  47.             if (mh = (PF *)GetResource('PLAY', PLAY)) {
  48.                 HLock(mh);
  49.                 mp = *mh;
  50.                 PtoCstr(p->text);
  51.                 MorsePlay(p->text, p->frequency, p->volume, p->speed);
  52.                 ReleaseResource(mh);
  53.             }
  54.         }
  55.         ReleaseResource(h);
  56.     }
  57. }
  58.